package impl

import (
	"context"
	"gitee.com/kordar/goadmin/admin/service"
	"gitee.com/kordar/goadmin/reader"
	"github.com/kordar/ginsys/resp"
	"github.com/kordar/gocrud"
	gocrudgorm "github.com/kordar/gocrud-gorm"
	"gorm.io/gorm"
	"labelsys/dataset/model"
	"labelsys/dataset/vo"
)

type DatasetImageServiceImpl struct {
	*gocrud.CommonResourceService
	db          *gorm.DB
	dictService service.DictService
}

func NewDatasetImageService(db *gorm.DB, dictService service.DictService) *DatasetImageServiceImpl {
	return &DatasetImageServiceImpl{db: db, dictService: dictService}
}

func (service DatasetImageServiceImpl) ResourceName() string {
	return "dataset-image"
}

func (service DatasetImageServiceImpl) Configs(ctx context.Context) map[string]interface{} {
	locale := resp.GetLocale(ctx)
	return map[string]interface{}{
		"state":       service.dictService.Options("dataset-image.state", locale),
		"audit":       service.dictService.Options("dataset-image.audit", locale),
		"create-type": service.dictService.Options("dataset-image.create-type", locale),
	}
}

func (service DatasetImageServiceImpl) Search(body gocrud.SearchBody) gocrud.SearchVO {
	searchBody := gocrudgorm.NewGormSearchBody(body)
	db := searchBody.GormQuery(service.db, nil).Model(&model.LabelsysDatasetImage{})
	queryReader := reader.NewQueryReader(db, int(body.Page), int(body.PageSize))
	var datasetImageVOS []*vo.DatasetImageVO
	return queryReader.SearchVO(&datasetImageVOS, nil)
}

func (service DatasetImageServiceImpl) Remove(body gocrud.RemoveBody) error {
	return body.Delete(&model.LabelsysDatasetImage{}, service.db, nil)
}
